import axios from '@/api/axios'
import {Notify} from 'vant'
import WxSdk from '../lib/wx-sdk'

// 响应拦截器
axios.interceptors.response.use(response => {
    return Promise.resolve(response)
}, (error) => {
    const err = JSON.parse(JSON.stringify(error))
    console.log(err)
    if (error.code) {
        if (err.config && err.config.url !== '/api/v1.0/user/getUserInfo') {
        } else {
            Notify({
                type: 'warning',
                message: err.msg
            })
        }
    }
    // console.log(err)
    if ((err.message && err.message.includes('status code 401')) && !err.config.url.includes('/api/v1.0/user/getUserInfo')) {
        if (window.__wxjs_environment === 'miniprogram') {
            window.$wxMini.switchTab({
                url: `/pages/admin/index`
            })
        } else {
            window.location.href = './mobile.html#/login'
        }
    }
    return Promise.reject(error)
})

export default axios
